package structural.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyInvocationHandler implements InvocationHandler {

    private Object target;
    public MyInvocationHandler(Object t){
        target = t;
    }
    /*通过特定的invocation handler来实现单一职责*/
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("开始代理工作，计时开始");
        long start = System.currentTimeMillis();
        Object result = method.invoke(target,args);
        long end = System.currentTimeMillis();
        System.out.println("结束代理工作，计时结束，共计时间 "+(end-start)+" ms");
        return result;
    }
}
